import URI from '@/services/uri';
import {
  requestPostByToken,
  requestGetByToken,
  requestPutByToken,
  requestDeleteByToken,
} from '@/utils/request';

export async function listArea() {
  const response = await requestGetByToken({ url: URI.common.getArea });
  if (Array.isArray(response)) {
    return response.map(item => ({
      ...item,
      id: item.id,
      areaCode: item.area_code,
      areaDescEn: item.area_desc_en,
      areaDescZh: item.area_desc_zh,
      status: item.status,
    }));
  }
  return response;
}

export async function listWorkerType() {
  const response = await requestGetByToken({
    url: URI.common.getWorkerType,
  });
  if (Array.isArray(response)) {
    return response.map(item => ({
      ...item,
      codeName: item.code_name,
      nameEn: item.name_en,
      nameZh: item.name_zh,
      skillLevel: item.skill_level,
      skillType: item.skill_type,
    }));
  }
  return response;
}

export async function query() {
  return requestGetByToken({ url: '/api/users' });
}
export async function queryCurrent() {
  return requestGetByToken({ url: '/api/currentUser' });
}
export async function queryNotices() {
  return requestGetByToken({ url: '/api/notices' });
}
